package com.apes.fico.engine.service;

import com.apes.fico.engine.model.VoucherTemplateGroup;
import com.apes.fico.engine.repository.VoucherTemplateGroupRepository;
import com.apes.framework.api.DomainService;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @ClassName VoucherTemplateGroupService
 * @Description TODO
 * @Author pengyb
 * @Date 2019/1/30 16:37
 * @Version 1.0
 **/
@Service("voucherTemplateGroupService")
public class VoucherTemplateGroupService extends DomainService {
    @Autowired
    private VoucherTemplateGroupRepository voucherTemplateGroupRepository;

    public VoucherTemplateGroup create(SimpleRequest request) {
        VoucherTemplateGroup voucherTemplateGroup = request.getO(VoucherTemplateGroup.class);
        voucherTemplateGroup.setCreateDate(new Date());
        return voucherTemplateGroupRepository.save(voucherTemplateGroup);
    }

    public VoucherTemplateGroup update(SimpleRequest request) {
        VoucherTemplateGroup voucherTemplateGroup = request.getO(VoucherTemplateGroup.class);
        voucherTemplateGroup.setUpdateDate(new Date());
        return voucherTemplateGroupRepository.saveAndFlush(voucherTemplateGroup);
    }
}
